﻿using System;
using System.IO;
using System.Windows.Forms;
using FBProject.BusinessLogic;
using System.Reflection;
using System.Collections.Generic;

namespace FBProject
{
    public partial class FMain : Form
    {
        public FMain()
        {
            InitializeComponent();

            this.Text = ApplicationHelper.GetApplicationNameAndVersion(Assembly.GetExecutingAssembly().GetName());
        }

        private void SynchronizeButton_Click(object sender, EventArgs e)
        {
            Enabled = false;

            DialogResult synchronizationResult;
            IList<TaskDifference> taskDifferences;
            using (var progressForm = new FSynchronizationProgress(FBExportFileSelectorControl.FBExportFileName))
            {
                synchronizationResult = progressForm.ShowDialog(this);
                taskDifferences = progressForm.TaskDifferences;
            }

            if (synchronizationResult == System.Windows.Forms.DialogResult.OK)
            {
                using (var taskDifferencesForm = new FTaskDifferences(taskDifferences))
                {
                    taskDifferencesForm.ShowDialog(this);
                }
            }

            Enabled = true;
        }

        private void SetSynchronizeButtonEnabled()
        {
            SynchronizeButton.Enabled = (FBExportFileSelectorControl.FBExportFileOk && ActiveProjectInfoControl.ActiveProjectOk);
        }

        private void ActiveProjectInfoControl_ActiveProjectChanged(object sender, EventArgs e)
        {
            SetSynchronizeButtonEnabled();
        }

        private void FBExportFileSelectorControl_FBExportFileChanged(object sender, EventArgs e)
        {
            SetSynchronizeButtonEnabled();
        }

    }
}
